import { initTree } from "@/views/common/menuTree";

export default {
    type: 'form',
    name: 'role-menu-form',
    messages:{
      validateFailed:''
    },
    api: '/upms/admin/role/assign/menu',
    body: [
      {
        type: 'select',
        name: 'systemId',
        label: '子系统',
        selectFirst: true,
        source: '/upms/admin/system/select'
      },
      {
        type: 'input-tree',
        name: 'menuIds',
        label: '菜单权限',
        multiple: true,
        withChildren: true,
        cascade: true,
        joinValues: false,
        extractValue: true,
        source: {
          url: "/upms/admin/menu/grant/list/tree?systemId=${systemId}&roleId=${id}",
          adaptor: function (payload, response, api, context) {
            if(payload.data){  
              initTree(payload.data.menus);
            }
            payload.data = {
              options: payload.data.menus,
              value: payload.data.selectedMenuIds,
            }
            return {
                ...payload
            };
          },
          sendOn: '${systemId}'
        },
      },
      {
        type: 'hidden',
        name: 'roleId',
        value: '${id}'
      }
    ]
  }